﻿using System.Collections.Generic;
using JSAnalyse.Core;
using JSAnalyse.Test.Helper;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace JSAnalyse.Test
{
    [TestClass]
    public class GlobalDefinitionTest
    {
        /// <summary>
        /// A simple dependency check test
        /// </summary>
        [TestMethod]
        public void GlobalSimpleDependencyTest()
        {
            var mainJs = "Main.js";
            var ref1Js = "Ref1.js";

            var allowedDependencies = new List<AllowedDependencyTest>();

            var fileInfoMain = new JavascriptFileInfo(mainJs,
                                                      @"function function1() {
                                                            return 'Test';
                                                        }");
            var fileInfoRef1 = new JavascriptFileInfo(ref1Js,
                                                      @"function function2() {
                                                            return function1();
                                                        }");

            var dependencyRunner = new DependencyRunner(
                new List<JavascriptFileInfo> { fileInfoMain, fileInfoRef1 },
                new AllowedDependenciesTest(allowedDependencies)
                );

            var result = dependencyRunner.Start();
            var mainResult = GeneralHelper.GetResultItem(result, mainJs);
            var ref1Result = GeneralHelper.GetResultItem(result, ref1Js);
            Assert.AreEqual(2, result.Count);

            Assert.IsNotNull(mainResult);
            Assert.AreEqual(0, mainResult.WrongFileDependencies.Count);

            Assert.IsNotNull(ref1Result);
            Assert.AreEqual(1, ref1Result.WrongFileDependencies.Count);
        }
    }
}
